<?

if(!defined(SCOT_COOCCURRENCE_SERIALIZER)) {
	define('SCOT_COOCCURRENCE_SERIALIZER', true);

	class CooccurrenceSerializer {
		var $scotModel = null;
		function CooccurrenceSerializer($model) {
			if(SCOT_DEBUG) echo('Call : CooccurrenceSerializer->RDFSerializer()<br>');
			
			$this->scotModel = $model;
		}
		
		function serialize($path) {
			if(SCOT_DEBUG) echo('Call : CooccurrenceSerializer->serialize()<br>');
			
			$data = "COOCCURRENCE,A FREQUENCY,R FREQUENCY,TAG 1 C FREQUECNT,TAG 2 C FREQUECNY\n";
			
			foreach($this->scotModel->getCooccurrenceList() as $cooccurrence) {
				if(count($cooccurrence->getTagIDList()) == 2) {
					$tagList = $cooccurrence->getTagList();
					$data .= $tagList[0]->getName()." and ".$tagList[1]->getName().",";
					$data .= $cooccurrence->getAFrequency().",";
					$data .= sprintf("%1\$.2f", $cooccurrence->getRFrequency($this->scotModel->getTotalCooccurrenceFrequency())).",";
					$date .= sprintf("%1\$.2f", ($tagList[0]->getCAFrequency() * $tagList[0]->getRFrequency($this->scotModel->getTotalTagFrequency()) / 100)).",";
					$date .= sprintf("%1\$.2f", ($tagList[1]->getCAFrequency() * $tagList[1]->getRFrequency($this->scotModel->getTotalTagFrequency()) / 100))."\n";
				}
			}
			
			$data .= "TOTAL,".($this->scotModel->getTotalTagFrequency()).",100,0,0\n";
			
			$fh = fopen($path, 'w');
			fwrite($fh, $data);
			fclose($fh);
		}
	}
}
?>